package com.cms.edm.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cms.edm.entity.TeacherEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cms.edm.entity.CourseEntity;
import com.cms.edm.service.CourseService;
import com.cms.common.utils.PageUtils;
import com.cms.common.utils.R;



/**
 * 
 *
 * @author weixiaochun
 * @email xiaochun0121@163.com
 * @date 2022-03-15 10:48:10
 */
@RestController
@RequestMapping("edm/course")
public class CourseController {
    @Autowired
    private CourseService courseService;

    /**
     * 课程教师选择
     */
    @RequestMapping("/selectTeacher")
    public R selectTeacher(@RequestParam String courseName){
        List<TeacherEntity> teacherEntities = courseService.selectTeacher(courseName);
        return R.ok().put("teachers", teacherEntities);
    }

    /**
     * 学期课程选择
     */
    @RequestMapping("/selectCourseByGrade")
    public R selectCourseByGrade(@RequestParam String grade){
        QueryWrapper<CourseEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("grade", grade);
        List<CourseEntity> courseEntities = courseService.list(wrapper);
        return R.ok().put("course", courseEntities);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("edm:course:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = courseService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("edm:course:info")
    public R info(@PathVariable("id") Long id){
		CourseEntity course = courseService.getById(id);

        return R.ok().put("course", course);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("edm:course:save")
    public R save(@RequestBody CourseEntity course){
		courseService.save(course);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("edm:course:update")
    public R update(@RequestBody CourseEntity course){
		courseService.updateById(course);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("edm:course:delete")
    public R delete(@RequestBody Long[] ids){
		courseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
